package com.kelvin.paopao.utils;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.v4.app.NotificationCompat;

import com.kelvin.paopao.R;
import com.kelvin.paopao.module.main.date.dateperson.DatePersonActivity;
import com.kelvin.paopao.module.main.date.mydate.MyDateActivity;
import com.kelvin.paopao.module.peisong.mypeisong.MyPeisongActivity;
import com.kelvin.paopao.module.peisong.mypeisong.peisongperson.PeisongPersonActivity;

/**
 * Created by MCK on 2017/3/17.
 */

public class NotificationUtil {

    /**
     * 通知栏显示系统通知
     */
    public static void notifyNotice
    (Context context, String typeStr, int oid, String content, String id) {
        NotificationManager notificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

        int type = 0;
        Intent intent = null;
        if (typeStr.equals("约会报名")) {
            intent = new Intent(context, DatePersonActivity.class);
            intent.putExtra("id", oid);
            type = Constant.date_notifyID;
        } else if (typeStr.equals("配送报名")) {
            intent = new Intent(context, PeisongPersonActivity.class);
            intent.putExtra("id", id);
            type = Constant.peisong_notifyID;
        } else if (typeStr.equals("配送确认")) {
            intent = new Intent(context, MyPeisongActivity.class);
            intent.putExtra("isMyAsk", true);
            type = Constant.peisong_notifyID;
        } else if (typeStr.equals("约会确认")) {
            intent = new Intent(context, MyDateActivity.class);
            intent.putExtra("isMyAsk", true);
            type = Constant.date_notifyID;
        }

        builder.setContentTitle("新的消息").setContentText(content).
                setWhen(System.currentTimeMillis()).setAutoCancel(true).
                setSmallIcon(R.mipmap.ic_launcher).setOngoing(false).
                setDefaults(Notification.DEFAULT_SOUND).
                setContentIntent(PendingIntent.getActivity(context, 0, intent, 0));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            builder.setPriority(Notification.PRIORITY_MAX);
        }
        Notification notification = builder.build();
        notificationManager.notify(type, notification);
    }
}
